package com.example.tuter.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tuter.R;
import com.example.tuter.activity.util.PageResultHandler;
import com.example.tuter.activity.util.PageResultHelper;
import com.example.tuter.adapter.MyCollectAdapter;
import com.example.tuter.entity.Message;
import com.example.tuter.entity.PageResult;
import com.example.tuter.entity.Post;
import com.example.tuter.util.Constant;
import com.example.tuter.util.UpdateUIUtil;
import com.example.tuter.util.httpUtil.HttpFunction.UserAPI;

import retrofit2.Call;

public class MyCollectActivity extends BaseActivity implements PageResultHandler<Post> {

    private static final String TAG = MyCollectActivity.class.getSimpleName();



    private PageResultHelper<Post> pageHelper = new PageResultHelper<Post>();
    private UserAPI userAPI;
    private MyCollectAdapter myCollectAdapter;
    private ImageView imageView_back;




    @Override
    public Call<Message<PageResult<Post>>> getDataByPage(Integer pageNo) {
        return userAPI.myCollect(pageNo,null);
    }

    @Override
    public void updateUI() {
        UpdateUIUtil.updateUIBySingleAdapter(myCollectAdapter);
    }



    @Override
    protected void initData() {
        userAPI = Constant.r.create(UserAPI.class);
        myCollectAdapter = new MyCollectAdapter(pageHelper.getData(), this);
    }

    @Override
    protected void bindEvent() {
        imageView_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        //点击跳转
        myCollectAdapter.setRecyclerItemClickListener(new MyCollectAdapter.OnRecyclerItemClickListener() {
            @Override
            public void onRecyclerItemClick(int position) {

                Intent intent = new Intent(MyCollectActivity.this, ViewPostActivity.class);
                intent.putExtra("post", pageHelper.getData().get(position));
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initView() {

        setContentView(R.layout.activity_my_collect);

        RecyclerView recyclerView = findViewById(R.id.activity_mycollect_recyclerView);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);


        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(myCollectAdapter);
        pageHelper.addPageScroll(this,recyclerView);
        imageView_back = (ImageView) findViewById(R.id.activity_mycollect_imageView);
    }

    @Override
    protected int getLayoutID() {
        return R.layout.activity_my_collect;
    }
}
